#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int ret = 0x3f3f3f3f;
    for (char c = 'a'; c <= 'z'; ++c)
    {
        int count = 0;
        for (auto ch : s)
        {
            count += min(abs(c - ch), 26 - abs(c - ch));
        }
        ret = min(ret, count);
    }
    cout << ret << endl;
    return 0;
}